package org.bet.dao.mongo;

import java.util.Collection;
import java.util.List;

import org.bet.dao.BioFeatureSetDao;
import org.bet.domain.BioFeatureEntry;
import org.bet.domain.BioFeatureSet;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

public class MongoDBBioFeatureSetDao implements BioFeatureSetDao {
	private MongoTemplate mongoTemplate;

	public MongoTemplate getMongoTemplate() {
		return mongoTemplate;
	}

	public void setMongoTemplate(MongoTemplate mongoTemplate) {
		this.mongoTemplate = mongoTemplate;
	}

	@Override
	public void saveOrUpdateBioFeatureSet(BioFeatureSet bioFeatureSet) {
		if(bioFeatureSet != null){
			mongoTemplate.save(bioFeatureSet);
		}
	}

	@Override
	public void saveOrUpdateBioFeatureEntries(Collection<BioFeatureEntry> bioFeatureEntries) {
		if(bioFeatureEntries != null){
			for(BioFeatureEntry entry : bioFeatureEntries){
				mongoTemplate.save(entry);
			}
		}
	}

	@Override
	public BioFeatureSet getBioFeatureSet(String id) {
		return mongoTemplate.findOne(new Query(new Criteria("id").is(id)), BioFeatureSet.class);
	}

	@Override
	public List<BioFeatureEntry> getAllBioFeatureEntriesOf(String featureSetId) {
		return mongoTemplate.find(new Query(new Criteria("ownerId").is(featureSetId)), BioFeatureEntry.class);
	}
	
	
}
